﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Security.Cryptography;
using System.Text;

/// <summary>
///ConvertData 的摘要说明
/// </summary>
public class ConvertData
{
	public ConvertData()
	{
		//
		//TODO: 在此处添加构造函数逻辑
		//
	}

    public static string ToMD5(string str)
    {
        MD5 m = new MD5CryptoServiceProvider();
        byte[] s = m.ComputeHash(UnicodeEncoding.UTF8.GetBytes(str));
        return BitConverter.ToString(s);
    }

    public static TimeSpan ToTimeSpan(int n)
    {
        int d = n / (60 * 24);
        n -= d * (60 * 24);
        int h = n / 60;
        n -= h * 60;
        int m = n;
        TimeSpan t = new TimeSpan(d,h,m,0);
        return t;
    }

    public static DateTime StrToDate(string str)
    {
        int i;
        int year = 0;
        for(i=0;str[i]!='-';i++)
        {
            year = year * 10 + str[i] - '0';
        }
        i++;
        int month = 0;
        for (; str[i] != '-'; i++)
        {
            month = month * 10 + str[i] - '0';
        }
        i++;
        int day = 0;
        for (; i < str.Length; i++)
        {
            day = day * 10 + str[i] - '0';
        }
        DateTime dt = new DateTime(year, month, day);
        return dt;
    }
}